//
//  JKEmoticonTextAttachment.swift
//  Swift表情键盘
//
//  Created by 王冲 on 2018/1/20.
//  Copyright © 2018年 希爱欧科技有限公司. All rights reserved.
//

import UIKit

class JKEmoticonTextAttachment: NSTextAttachment {

    // 保存对应表情的文字
    var chs: String?
    
    /// 根据表情模型, 创建表情字符串
    class func imageText(emoticon: JKEmoticon, font: UIFont) -> NSAttributedString{
        
        // 1.创建附件
        let attachment = JKEmoticonTextAttachment()
        attachment.chs = emoticon.chs
        attachment.image = UIImage(contentsOfFile: emoticon.imagePath!)
        // 设置了附件的大小
        let s = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: s, height: s)
        // 2. 根据附件创建属性字符串
        return NSAttributedString(attachment: attachment)
    }
}
